require "Common/define"
require "Logic/Config"
require "Common/functions"

RedDotsTacticsHandler ={};
local this = RedDotsTacticsHandler;

local tacticsConfig = nil;

function RedDotsTacticsHandler.init()
    CloseEvent(Config.EventType.Fresh_Level,this.update);
    CloseEvent(Config.EventType.Fresh_Tactics,this.update);

    ListenEvent(Config.EventType.Fresh_Level,this.update);
    ListenEvent(Config.EventType.Fresh_Tactics,this.update);

    if tacticsConfig == nil then
        tacticsConfig = G.dataTable["t_tactics"];
    end

    return this;
end

--参数1： 阵法id，nil代表检查所有
function RedDotsTacticsHandler.getFlag(...)
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.Tactics,false) then
        local tacticsId = ...;
        local tacticses = nil;
        if tacticsId~=nil then
            tacticses ={};
            local tactics = logicMgr.TacticsManager.getTacticsInfo(tacticsId);
            if tactics~=nil then
                table.insert(tacticses,tactics);
            end
        else
            tacticses = logicMgr.TacticsManager.getTacticsList();
        end

        for i = 1, #tacticses do
            if logicMgr.TacticsManager.isReachLevelPremise(tacticses[i].tacticsId) and tacticses[i].isActivate == false then
                return Config.RedDotsFlagState.Needful;
            end
        end
    end
    return Config.RedDotsFlagState.None;
end

function RedDotsTacticsHandler.update()
    RedDotsManager.addBroadcast(Config.RedDotsType.Tactics);
end